﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using OpenChart.Entities;

namespace TestForm
{
    public partial class FormPieChart : Form
    {
        private DataTable _testDt;

        public FormPieChart()
        {
            InitializeComponent();
            this.AddTestData();
            this.InitChart();
        }

        private void AddTestData()
        {
            _testDt = new DataTable();
            _testDt.Columns.Add("Country",typeof(string));
            _testDt.Columns.Add("Number",typeof(int));
            DataRow row;
            
            row = _testDt.NewRow();
            row["Country"] = "中国人";
            row["Number"] = 13;
            _testDt.Rows.Add(row);

            row = _testDt.NewRow();
            row["Country"] = "印度人";
            row["Number"] = 12;
            _testDt.Rows.Add(row);

            row = _testDt.NewRow();
            row["Country"] = "美国人";
            row["Number"] = 3;
            _testDt.Rows.Add(row);

            row = _testDt.NewRow();
            row["Country"] = "印度尼西亚";
            row["Number"] = 2;
            _testDt.Rows.Add(row);

            row = _testDt.NewRow();
            row["Country"] = "巴西";
            row["Number"] = 2;
            _testDt.Rows.Add(row);

            row = _testDt.NewRow();
            row["Country"] = "其它人";
            row["Number"] = 28;
            _testDt.Rows.Add(row);
        }

        private void InitChart()
        {
            this.chart1.ChartArea.Data = _testDt;
            this.chart1.ChartArea.ChartType = OpenChart.Entities.Enums.ChartType.Pie;
            StringInfo title = new StringInfo();
            title.Value = "PieChart";
            title.Size = 14;
            title.Color = Color.Salmon;
            this.chart1.ChartArea.ChartTitle = title;
            chart1.ChartArea.XValueMember = "Country";

            Series series = new Series();
            series.YValueMember = "Number";
            this.chart1.ChartArea.Series.Add(series);
        }
    }
}
